package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.server.TanhuaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
@Slf4j
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 推荐朋友
     * @param recommendUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto){
        PageResult pr = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pr);
    }

    /**
     * 超看佳人信息
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long id){
        log.info("id = {}" , id);
        TodayBest todayBest = tanhuaService.findPersonalInfo(id);
        return ResponseEntity.ok(todayBest);
    }


    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long id){
        log.info("id = {}",id);
        String question = tanhuaService.queryQuestionById(id);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map){
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = (String) map.get("reply");
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 首页探花
     */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list = tanhuaService.queryCradsList();
        return ResponseEntity.ok(list);
    }

    /**
     * 探花-喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long id){
          tanhuaService.likeUser(id);
          return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId){
         tanhuaService.dislikeUser(likeUserId);
         return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> vo =this.tanhuaService.queryNearUser(gender,distance);
        return ResponseEntity.ok(vo);
    }

}